#ifndef WIDGETVARIANTCONTAINER_H
#define WIDGETVARIANTCONTAINER_H

#include <DefineLibUiQt.h>
#include <QtWidgets/QWidget>
#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QScrollArea>
#include <QtCore/QVariant>
#include <WidgetVariant.h>
#include <EItem.h>
#include <EItemMetaProperty.h>
#include <EControllerQtProperty.h>

namespace Ui {
class WidgetVariantContainer;
}

class LIB_UI_QT_DLL WidgetVariantContainer : public QWidget
{
    Q_OBJECT

public:
    explicit WidgetVariantContainer(QWidget *parent = 0);
	virtual ~WidgetVariantContainer();

	void addWidget(QWidget* widget_ptr);
	QWidget* getWidget(int index);
	QVBoxLayout* getTheLayout();
	void cleanAllWidget();
    void filtWidget(const QString& filterStr);

	void buildThis();

    // QWidget* findWidgetByPropertyName(const QString& name);

    EItemPtr getEItemPtr();

    /**loop all child QCombobox,QDoubleSpinBox,QSpinBox and install eventFilter to avoid mouse's wheel event*/
    void installEventFilterForChildren();

    EControllerPtr getController();

public slots:
    //this functon is called when tree item is selected, and the m_itemBasePtr will be set.
    void slotSelectItemBase(EItemPtr ibp);
    //this functon is called when tree item is disselected, and the m_itemBasePtr will be set.
    void slotDisSelectItemBase(EItemPtr ibp);

    // void slotModuleSelected(Module* modulePtr);
    // void slotModuleNoSelect();

    //connected with widgetVariant's signal signalVariantChanged;
    //the connection is build when addWidget function is called
    void slotSubVariantWidgetChanged(EItemMetaPropertyPtr p);

    void slotButtonRefresh(bool boolValue);
    void slotButtonSearchClicked(bool boolValue);
    void slotClearAll();
    // void slotRemoveButton();
signals:
    // void signalRefresh();

    //this signal is connected by outer project, for example a HandlerVarOsg class.
    void signalPropertyChanged(EItemPtr ibp, EItemMetaPropertyPtr p);
private:
    bool eventFilter(QObject* target, QEvent* event);

    Ui::WidgetVariantContainer *ui;
    
	QVBoxLayout* m_layout;
	std::vector<QWidget*> m_widgetList;
    //
    EItemPtr m_itemBasePtr;

    EControllerQtPropertyPtr m_controllerProperty;
    // Module* m_currentModule;
};

#endif // WIDGETVARIANTCONTAINER_H
